bin_dir           := ../../Release
project_name      := server
bin_name          := $(project_name)
full_bin_name     := $(bin_dir)/$(bin_name)

include_dirs      := /usr/include/qt4
root_include_dir  := ./api . ../
root_source_dir   := sources
source_subdirs    := .
compile_flags     := -I $(include_dirs)
link_flags        := -L$(bin_dir)
libraries         := -lta_project_manager -lQtCore
build_flags       := -O0

qt_files          := sources/srv_time_trigger.hpp
qt_files_paths    := $(addprefix ../../$(project_name)/, $(qt_files))
moc_files         := $(qt_files_paths:%.hpp=%_moc.cpp)
 
relative_include_dirs  := $(addprefix ../../$(project_name)/, $(root_include_dir))
relative_source_dirs   := $(addprefix ../../$(project_name)/$(root_source_dir)/, $(source_subdirs))
objects_dirs           := $(addprefix $(root_source_dir)/, $(source_subdirs))
objects                := $(patsubst ../../$(project_name)/%, %, $(wildcard $(addsuffix /*.c*, $(relative_source_dirs)))) $(patsubst ../../$(project_name)/%, %, $(moc_files))
objects                := $(objects:.cpp=.o)
objects                := $(objects:.c=.o)

all : $(full_bin_name)
 
$(full_bin_name) : obj_dirs $(objects) 
	g++ -o $@ $(objects) $(link_flags) $(libraries)
 
obj_dirs :
	mkdir -p $(objects_dirs)
 
VPATH := ../../$(project_name)/

%.o : %.cpp
	g++ -o $@ -c $< $(compile_flags) $(build_flags) $(addprefix -I, $(relative_include_dirs))
 
%.o : %.c
	g++ -o $@ -c $< $(compile_flags) $(build_flags) $(addprefix -I, $(relative_include_dirs))
	
%_moc.cpp: %.hpp
	moc $< -o $@
 
.PHONY : clean
 
clean :
	rm -rf $(full_bin_name) $(objects)
 
include $(wildcard $(addsuffix /*.d, $(objects_dirs)))

